package JavaUtils.CSUtils;

import JavaUtils.CSUtils.Log.CLog;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CConfig {
    static final String tag = "CConfig";
    Map<String, String> configMap = new HashMap();

    public static CConfig S_LoadData(String currPath) {
        CConfig cfg = new CConfig();
        //String fileName = currPath + "build_config.txt";
        CLog.i(tag, currPath);

        List<String> list = CFile.ReadAllLines(currPath);
        if (list == null) {
            CLog.ex(tag, "build.build_config.......不存在无法打包....." + currPath);
            return null;
        }
        for (String ss : list) {
            if (ss.length() < 2) {
                continue;
            }
            String[] sss = CString.string0_split(ss, "[= ;]", true);
            if (sss.length < 2) {
                continue;
            }
            String key = sss[0].trim().toLowerCase();
            key = S_ClearStringHead(key);
            String value = sss[1].trim();
            CLog.i(tag, key + "__________" + value);
            String put = cfg.configMap.put(key, value);

        }
        return cfg;
    }

    static String S_ClearStringHead(String str) {
        int length = str.length();
        char[] chars = new char[length];
        str.getChars(0, length, chars, 0);
        int errorPosi = -1;
        for (int v = 0; v < chars.length; v++) {
            if (chars[v] != 35 && (chars[v] < 48 || chars[v] > 122)) {
                //System.out.println("错误......" + chars[v]);
                errorPosi = v;
            } else {
                //System.out.println("数据......................." + chars[v]);
                break;
            }
        }
        if (errorPosi < 0) {
            return str;
        }
        return str.substring(errorPosi + 1);
    }

    public String GetString(String key) {
        if (configMap.containsKey(key)) {
            return configMap.get(key);
        }
        return "";
    }

    public int GetInt(String key) {
        if (configMap.containsKey(key)) {
            String ss = configMap.get(key);
            try {
                int i3 = Integer.parseInt(ss);
                return i3;
            } catch (Exception ex) {
                return 0;
            }
        }
        return 0;
    }
}
